package com.member.server.domain.vo;

import com.alibaba.fastjson.JSON;
import com.member.server.domain.dto.MemAccInfoDTO;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author gaojx1993
 * @version 1.0
 * @description MemAccVO
 * @since 2023/7/12 11:15
 */
public class MemAccVO implements Serializable {

    private Long memberId;

    private String memberName;

    private Long totalBalance;

    private List<AccInfo> accInfos;

    public static MemAccVO copy(MemAccInfoDTO memAccInfoDTO) {
        MemAccVO memAccVO = new MemAccVO();
        memAccVO.setMemberId(memAccInfoDTO.getMember().getId());
        memAccVO.setMemberName(memAccInfoDTO.getMember().getName());
        memAccVO.setTotalBalance(memAccInfoDTO.getTotalBalance());
        memAccVO.setAccInfos(memAccInfoDTO.getAccounts().stream().map(acc -> {
                    AccInfo accInfo = new AccInfo();
                    accInfo.setId(acc.getId());
                    accInfo.setBalance(acc.getBalance());
                    accInfo.setType(acc.getType());
                    return accInfo;
                }).collect(Collectors.toList()));
        return memAccVO;
    }

    public Long getMemberId() {
        return memberId;
    }

    public void setMemberId(Long memberId) {
        this.memberId = memberId;
    }

    public String getMemberName() {
        return memberName;
    }

    public void setMemberName(String memberName) {
        this.memberName = memberName;
    }

    public Long getTotalBalance() {
        return totalBalance;
    }

    public void setTotalBalance(Long totalBalance) {
        this.totalBalance = totalBalance;
    }

    public List<AccInfo> getAccInfos() {
        return accInfos;
    }

    public void setAccInfos(List<AccInfo> accInfos) {
        this.accInfos = accInfos;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    public static class AccInfo implements Serializable {

        private Long id;

        private Integer type;

        private Long balance;

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public Integer getType() {
            return type;
        }

        public void setType(Integer type) {
            this.type = type;
        }

        public Long getBalance() {
            return balance;
        }

        public void setBalance(Long balance) {
            this.balance = balance;
        }

        @Override
        public String toString() {
            return JSON.toJSONString(this);
        }
    }
}
